<template>
	<div id="app">

		<van-loading v-if="loadShow" size="100px" color="red">加载中...</van-loading>
		<router-view  v-else></router-view>


	</div>




</template>

<script>
	export default {
		name: 'app',
		components: {

		},

		data() {
			return {
				keyNumber: [48, 49, 50, 51, 52, 53, 54, 55, 56, 57],
				event_card_no: '',
				lastTime: 0,
				outTime: 1000 *60 *2,
				currentTime: 0,
				tid: null,
				loadShow: true



			}
		},
		methods: {

			//获取url中的附带参数的值,因为有的时候获取的url不符vue——hash路由模式的url
			getValue(name) {
				let reg = new RegExp("(^|/?|&)" + name + "=([^&]*)(&|$)", "i");
				window.console.log("打印当前url");
				window.console.log(window.location.href);
				let match = window.location.href.match(reg);
				return match && match[2] || null;
			},

			getTemple() {
				this.axios.post('https://mianmianshi.com/cms/temple/user/temple', {

						id: this.$store.getters.getTid | localStorage.tid

					})
					.then((res) => {
						console.log("res->", res);
						this.$store.commit("setTempleData", res.data.data.data);
						localStorage.tid=res.data.data.data.id;
						localStorage.type=res.data.data.data.type;
						
						
						
						//localStorage.setItem("templeData",res.data.data.data);
						localStorage.setItem("templeData", res.data.data.data);

						console.log("templeData>", this.$store.getters.getTempleData);


					})
					.catch(function(error) {
						//this.mes = "未找到该用户，请检查是否输入错误";
						console.log(error);
					});
			},
			getWxPayInfo() {
				this.axios.get('https://mianmianshi.com/cms/temple/admin/getWeixinMes', {
						params: {
							tid: this.$store.getters.getTid | localStorage.tid
						}
					})
					.then((res) => {
						this.$store.commit("setWeixinMes", res.data);
						this.weixinMes = res.data;

						console.log("res.data:", res.data);
					})
					.catch((err) => {
						console.log("失败了");
						console.log(err)
					});
			},



			listenForCard() {

				let _this = this;




				let keyNumber = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57];
				let event_card_no = '';
				/* 监听键盘事件-读卡 */
				function fn(e) {
					event_card_no = '';

					for (let i = 0; i < 10; i++) {
						if (e.keyCode == keyNumber[i]) {
							event_card_no += i;
							break;
						} else if (e.keyCode == 13) {
							console.log(event_card_no);
							//event_card_no='';	
							document.removeEventListener("keydown", fn);
							console.log("移除了该事件");




							break;
						}
					}



				}

				document.addEventListener("keydown", fn);









				//addEventListener(type，handler，false/true)








				/* 	document.onkeydown=(e)=>{
						
						for(let i =0;i<10;i++){
							if(e.keyCode==this.keyNumber[i]){
								this.event_card_no+=i;
								break;
							}else if(e.keyCode==13){
								
								alert(this.event_card_no);
								this.event_card_no='';
								break;
							}
						}
					} */

			}


		},
		created() {

			if (this.$route.query.tid) {
				localStorage.setItem("tid", this.$route.query.tid);
				this.$store.commit("setTid", this.$route.query.tid);
				console.log('tid=======', this.$store.getters.getTid);
			} else {
				
				let tid = this.getValue("tid");
				localStorage.setItem("tid", tid);
				this.$store.commit("setTid", tid);
			}










			this.getTemple();
			this.getWxPayInfo();







		},
		mounted() {
			this.loadShow = false;
				
			console.log("window.location.href==========",window.location.href);
			
			let href=window.location.href;
			let  a = href.indexOf("#");
			let  target_url = href.substring(0, a);
		
			console.log("window.location.href==========",target_url);
			
			
			
			//console.log("this.$route--------",this.$route);
			

		


			//检测用户活动情况
			this.lastTime = new Date().getTime();
			document.addEventListener("click", () => {
				this.lastTime = new Date().getTime();
			});

			let intervalActive = setInterval(() => {
				if (new Date().getTime() - this.lastTime > this.outTime) {

					console.log("长时间未操作");
					this.$toast('长时间未操作或页面停留过久！');

					let tid = null;

					if (this.$store.getters.getTid) { //本地和vuex都可以调取tid
						tid = this.$store.getters.getTid;
					} else if (localStorage.tid) {
						tid = localStorage.tid;
					} else {
						alert("系统错误，请尝试重启！");
						return;
					}

					//刷新关键数据//

					//远程
					//window.location.href = "https://mianmianshi.com/jiesuan/demotest/#/?tid=" + tid;
						window.location.href = target_url+"#/?tid=" + tid;
					
					//本地
					//window.location.href = "https://192.168.0.101:8080/#/?tid=" + tid;
					//https://192.168.0.100:8080/#/?tid=1
					this.$store.commit("setTid", this.$route.query.tid);
					this.getWxPayInfo();
					this.getTemple();
					this.lastTime = new Date().getTime(); //重置最后时间




				}
			}, 3000);


			//this.listenForCard();




			//document.fullscreenEnabled

			//	setInterval(()=>{document.documentElement.webkitRequestFullScreen();},2000)

		}
	}
</script>

<style>
	#app {
		font-family: 'Avenir', Helvetica, Arial, sans-serif;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		text-align: center;
		color: #2c3e50;
		
		/*  margin-top: 60px; */
	}


	.title {

		color: #FFFFFF;
		font-size: 3.125 rem;
	}
	
	
	.topcss{
		 background: linear-gradient(90deg, #41A9B7,#4fd4e2, #41A9B7);height: 5rem;line-height: 5rem;
	}
</style>
